package org.zhu.LamadaInterface;

import java.util.*;
import java.util.function.*;

/**
 * Created by zhu yingzhi on 2017/8/29.
 * 函数式接口DEmo Function<T, R> T 作为输入 R作为输出
 * Predicate<T> -T作为输入，返回的boolean值作为输出
 * Consumer<T> T作为输入，无输出
 * Supplier<R> 无输入 只有返回
 * BinaryOperator<T> 支持同类型的两个输入，同类型的一个返回
 */

public class Client {

    public static void main(String[] args) {

        Person person = new Person("杨九日",1);
        // Function<T, R> -T作为输入，返回的R作为输出

        Function<Person,Person> function = (x) -> {x.setName("王小强");return x;};

        System.out.println(function.apply(person).getName());

        //Predicate<T> -T作为输入，返回的boolean值作为输出

        Predicate<String> pre = (x) ->{System.out.print(x);return false;};

        System.out.println(": "+pre.test("hello World"));

        //Consumer<T> - T作为输入，执行某种动作但没有返回值

        Consumer<String> con = (x) -> {System.out.println(x);};
        Consumer<String> con1 = System.out::println;

        con.accept("hello world");
        con1.accept("hello world");

        //Supplier<T> - 没有任何输入，返回T

        Supplier<String> supp = () -> {
            System.out.println("asdasd");return "Supplier";};
        System.out.println(supp.get());

        //BinaryOperator<T> -两个T作为输入，返回一个T作为输出，对于“reduce”操作很有用

        BinaryOperator<String> bina = (x, y) ->{System.out.print(x+" "+y);return "BinaryOperator";};

        System.out.println("  "+bina.apply("hello ","world"));


    }

    private static void CollectionSort() {
        List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");

        names.sort(new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                return b.compareTo(a);
            }
        });
    }


}
